# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=libplist
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.2.0
pkgrel=1
pkgdesc='A library to handle Apple Property List format in binary or XML (mingw-w64)'
arch=('any')
url='https://www.libimobiledevice.org/'
license=('GPL2+')
source=("${_realname}-${pkgver}.tar.gz"::https://github.com/libimobiledevice/libplist/archive/${pkgver}.tar.gz
        001-cython-module.patch
        002-dont-include-winmain-in-static.patch
        003-fix-py-soext.patch
        004-exports.patch)
depends=("${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-cython")
options=('staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-python")
sha256sums=('7e654bdd5d8b96f03240227ed09057377f06ebad08e1c37d0cfa2abe6ba0cee2'
            '48320c5667bdf724eeab6c73340cb4ddb6fdc98109938e7fa4438d35e4439a29'
            '65f4603a85f63567fac917dfb6e2d974078973ed815652817bedea80e4467016'
            '1cca10b36021da73e436bc3c7765170fcd2f053fb8ebcb2e361359345905788f'
            '51d783e6caa075cbf62c8c49554357b41ffa930decdb468cfe57cd5c414526de')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-cython-module.patch
  patch -p1 -i ${srcdir}/002-dont-include-winmain-in-static.patch
  patch -p1 -i ${srcdir}/003-fix-py-soext.patch
  patch -p1 -i ${srcdir}/004-exports.patch

  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  CC=${MINGW_PREFIX}/bin/gcc \
  PYTHON=${MINGW_PREFIX}/bin/python3 \
  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --enable-static \
      --enable-shared

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  # || true because of FAIL: bigarraycmp .. File does not exists
  make check || true
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

  rm -f ${pkgdir}${MINGW_PREFIX}/lib/python*/site-packages/*.a
}
